[android] setting wallpaper through code

Posted by Javadid on Stack Overflow See other posts from Stack Overflow or by Javadid
Published on 2010-06-14T05:07:04Z Indexed on 2010/06/14 5:12 UTC
Read the original article Hit count: 227

hi Friends,

I was trying to make an app which also had the facility to let user select wallpaper he would like to set. I have managed this by calling the Gallery Intent. Once the user selects a specific image, the data path of the image is returned to me which then i preview to the user by setting the image onto an imageview.

The problem crops up when the image size (and/or resolution) is greater than what android expects. This results in failure of my module.

And as if this was not enough, wen the user tries to select some other wallpaper(and in my test case the "other" wallpaper was also of size >700kb) then the app crashes with the "OutOfMemoryException"...

Helppp me here guys!!!

For Gallery Intent i use:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE);

For setting the wallpaper i use:

InputStream is = getContentResolver().openInputStream(Uri.parse(uri_returned_from_intent)); 
Bitmap bgImage = BitmapFactory.decodeStream(is);//OutOfMemory error thrown here
setWallpaper(bgImage);

So i have 2 problems to deal with:

  1. How to crop the image before setting it as wallpaper...
  2. Cant understand y OutOfMemoryException is thrown, coz none of my image sizes exceed even 1mb... and i guess the VM budget in case Of N1 is 24Mb if m not mistaken...

© Stack Overflow or respective owner

Related posts about android

Related posts about image